// Copyright (c) 2011 The Kiwii Authors. All rights reserved.
// Use of this source code is governed by the New BSD License that can be
// found in the LICENSE file. See the AUTHORS file for names of contributors.

#ifndef KIWI_EPOLL_INCLUDED
#define KIWI_EPOLL_INCLUDED

#include "net/PollScheme.hxx"
#include <boost/scoped_array.hpp>
#include <sys/epoll.h>

namespace kiwii {
  namespace net {

    class EPoll : public PollScheme {
    public:
      EPoll();
      ~EPoll();

      //noncopyable
      EPoll(EPoll const& rhs) = delete;
      EPoll& operator=(EPoll const& rhs) = delete;

      virtual void addEvent(int fd, unsigned int newEvents, unsigned int oldEvents);
      virtual void delEvent(int fd, unsigned int ev2Del, unsigned int oldEvents);
      virtual void poll(struct timeval const* timeout, std::vector<FiredIOEvent>& fired);

    private:
      int epollfd_;
      int nfds_; // number of registered file descriptors
      boost::scoped_array<struct epoll_event> events_;
      int bufsize_; // size of events_ array
    };

  }
}

#endif
